<template>
<div>
  <Table border :columns="columns" :data="data" >
    <template slot-scope="{ row }" slot="informationDO.name">
      <strong>{{row.informationDO.name  }}</strong>
    </template>
    <template slot-scope="{ row, index }" slot="action">
      <Button type="primary" size="small" style="margin-right: 5px" @click="update(row)">归还</Button>
    </template>
  </Table>
</div>
</template>

<script>
export default {
  name: "Library",
  data(){
      return{
        columns:[
          {
            title: '已借书籍',
            slot: 'informationDO.name'
          },
          {
            title:"借阅时间",
            key:'lend_date'
          },
          {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
        ],
         data:[] 
      }
     
  },
  methods:{
      getBook(){
        let data={
          id:this.getUser.id,
        }
        this.http.post("/getBook",this.qs.parse(data)).then(res=>{
          if (res.data){
            this.data=res.data
            console.log(res.data)
          }else {

          }
        })
      },
    update(row){
      let data={
        type:'已归还',
        id:row.id
      }
      this.http.post("/updateback",this.qs.parse(data)).then(res=>{
        if (res.data){
          this.$Message.success("归还成功")
          this.getBook();
        }else {
          this.$Message.error("归还失败")
        }
      })
    }
  },
  mounted() {
    this.getBook()
  },
  computed:{
    getUser(){
      return this.$store.state.user
    }
  }

  
}
</script>

<style scoped>

</style>
